{% extends "base_generic.html" %}

{% block title %}{{ book.title }} - 本地图书馆{% endblock %}

{% block content %}
<!-- 图书详情卡片 -->
<div class="card">
    <div class="card-header text-white" style="background-color: #FFDEAD;">
        <h1 class="h3 mb-0">{{ book.title }}</h1>
    </div>
    <div class="card-body">
        <div class="row">
            <div class="col-md-8">
                <h5 class="card-title">
                    <i class="fas fa-user me-2"></i>作者：
                    <a href="{{ book.author.get_absolute_url }}" class="text-decoration-none">
                        {{ book.author }}
                    </a>
                </h5>
                <p class="card-text mt-4">
                    <strong>简介：</strong><br>
                    {{ book.summary }}
                </p>
                <p class="card-text">
                    <strong>ISBN：</strong> {{ book.isbn }}
                </p>
                <p class="card-text">
                    <strong>语言：</strong> {{ book.language }}
                </p>
                <div class="mt-3">
                    <strong>类型：</strong><br>
                    {% for genre in book.genre.all %}
                    <span class="badge bg-secondary me-1">{{ genre }}</span>
                    {% endfor %}
                </div>
            </div>
            <div class="col-md-4">
                <div class="card">
                    <div class="card-header text-white" style="background-color: #FFB6C1;">
                        <h5 class="card-title mb-0">
                            <i class="fas fa-copy me-2"></i>馆藏信息
                        </h5>
                    </div>
                    <div class="card-body">
                        <ul class="list-group list-group-flush">
                        {% for copy in book.bookinstance_set.all %}
                            <li class="list-group-item">
                                <p class="mb-1">
                                    <strong>版本：</strong> {{ copy.imprint }}
                                </p>
                                <p class="mb-1">
                                    <strong>状态：</strong>
                                    {% if copy.status == 'a' %}
                                    <span class="badge bg-success">可借阅</span>
                                    {% elif copy.status == 'm' %}
                                    <span class="badge bg-warning text-dark">维护中</span>
                                    {% elif copy.status == 'o' %}
                                    <span class="badge bg-danger">已借出</span>
                                    {% elif copy.status == 'r' %}
                                    <span class="badge bg-info">已预订</span>
                                    {% endif %}
                                </p>
                                {% if copy.status == 'o' %}
                                <p class="mb-0">
                                    <strong>归还日期：</strong> {{ copy.due_back }}
                                </p>
                                {% endif %}
                            </li>
                        {% endfor %}
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 返回图书列表按钮 -->
<div class="card mt-3">
    <div class="card-body">
            <a href="{% url 'books' %}" class="btn btn-link">
                <i class="fas fa-arrow-left me-1"></i>返回图书列表
            </a>
    </div>
</div>

{% if user.is_authenticated %}
<div class="mt-4">
    <a href="#" class="btn btn-primary">
        <i class="fas fa-book me-2"></i>借阅此书
    </a>
    {% if user.is_staff %}
    <a href="{% url 'admin:catalog_book_change' book.id %}" class="btn btn-outline-secondary">
        <i class="fas fa-edit me-2"></i>编辑信息
    </a>
    {% endif %}
</div>
{% endif %}
{% endblock %}